﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LuatChoi;

namespace Utility
{
    public class VanCo
    {
        public List<NguoiChoi> DsNguoiChoi = new List<NguoiChoi>(2);
        public BanCo BanChoi { get; set; }
        public TrangThaiVanCo TrangThai { get; set; }

        public NguoiChoi this[Phe index]
        {
            get {
                switch (index)
                {
                    case Phe.Trang:
                        return DsNguoiChoi[0];
                    case Phe.Den:
                        return DsNguoiChoi[1];
                    default:
                        return null;
                }
            }
        }

        public NguoiChoi this[string Ten]
        {
            get
            {
                try
                {
                    return DsNguoiChoi.Single(n => n.Client.UserName.Equals(Ten));
                }
                catch
                {
                    return null;
                }
            }
        }

        public VanCo()
        {
            TrangThai = TrangThaiVanCo.ChuanBi;
            BanChoi = new BanCo();
        }

        public VanCo(ClientComputer trang, ClientComputer den)
            : this()
        {
            var qtrang = new NguoiChoi()
            {
                Client = trang,
                MauQuan = Phe.Trang
            };
            var qden = new NguoiChoi()
            {
                Client = den,
                MauQuan = Phe.Den
            };
            DsNguoiChoi.Add(qtrang);
            DsNguoiChoi.Add(qden);
        }
    }
}
